<style type="text/css">
    .fui-navbar ~ .fui-content, .fui-content.navbar{padding-bottom:0;}
    .text-danger2 {
        background: none;
    }
</style>
<div class='fui-page order-create-page'>
    <div class="fui-header">
        <div class="fui-header-left" href="javascript:;" ng-click="goback()">
            <a class="back"></a>
        </div>
        <div class="title">创建订单</div>
        <div class="fui-header-right"></div>
    </div>
    <div class='fui-content'>
			<div id="addressInfo" ng-show="pagedata.goods.isverify==0 && pagedata.goods.goodstype==0" class="fui-cell-group fui-address-group" style="margin-top:0.3rem;min-height:2rem">
				<div ng-if="pagedata.item.addressid" class="fui-cell" ng-click="pagedata.get_addresslist()">
					<div style="width:100%">
						<div class="fui-cell-text name bold" style="font-size:0.8rem">
							<span style="margin-right:20px">{{pagedata.item.address.name}}</span><span>{{pagedata.item.address.mobile}}</span>
						</div>
						<div class="fui-cell-text name" style="margin-top:5px">
							<!--预售完成-->
							<i class="fui-tag fui-tag-red">默认</i>
							<i class="fui-tag fui-tag-blue">家</i>
							{{pagedata.item.address.pcd.province+pagedata.item.address.pcd.city+pagedata.item.address.pcd.district+pagedata.item.address.address}}
						</div>
					</div>
					<div class="fui-cell-remark" ></div>
				</div>
				<div ng-if="!pagedata.item.addressid" class="fui-cellone" ng-click="pagedata.edit_address=1">
					<div class="fui-cellone-info c">
						<div class="text no-address" ><i class="icon jinyunicon icon-tianjia"></i> 添加收货地址</div>
					</div>
				</div>
			</div>
               <!--
                <div ng-if="pagedata.set.set_realname==0" class="fui-cell">
                    <div class="fui-cell-label">联系人</div>
                    <div class="fui-cell-info">
                        <input type="text" placeholder="请输入真实姓名" id="carrier_realname" data-show="{{pagedata.set.set_realname}}" value="{{pagedata.member.realname}" class="fui-input" maxlength="10">
                    </div>
                </div>
               
            
                <div ng-if="pagedata.set.set_mobile==0" class="fui-cell">
                    <div class="fui-cell-label">联系方式</div>
                    <div class="fui-cell-info">
                        <input type="tel" placeholder="请输入手机号码" id="carrier_mobile" data-show="{{pagedata.set.set_mobile}}" value="{{pagedata.member.mobile}" class="fui-input" maxlength="11">
                    </div>
                </div>
               -->
			 <div ng-if="pagedata.goods.type==0" class="fui-cell-group fui-cell-click">
                <div class="fui-cell" ng-if="pagedata.goods.stores.length>0">
                    <div class="fui-cell-text store">请选择兑换门店</div>
                    <div class="fui-cell-info" >
                      
                    </div>
					<div class="fui-cell-remark" ng-click="pagedata.showstores=true">
					 {{pagedata.selectstore.title}}
					</div>
                </div>
            </div>
			<div ng-if="pagedata.goods.is_moretype==1" class="fui-cell-group">
				<div class="fui-cell">
					<div class="fui-cell-text flex">
						<span class="price" style="text-align: left;">
							<span class="big" ng-if="pagedata.goods.mincredit>0">{{pagedata.goods.mincredit}}</span>
							<span class="big" ng-if="pagedata.goods.mincredit<=0">{{pagedata.post.taocan.credit}}</span>{{pagedata.post.taocan.credit_title || '积分'}}
							<span ng-if="pagedata.post.taocan.money>0" style="font-size: 0.8rem;font-weight: bold;padding-right: 0.1rem;"> +&yen;{{pagedata.post.taocan.money}}</span>
						</span>
					</div>
					<div class="fui-cell-remark" ng-click="pagedata.showcreditmore=true;">
						更多兑换方式
					</div>
				</div>
			 </div>
        <div class="fui-list-group goods-list-group" style="background:#fff">
            <a href="javascript:;" ng-click="access_json('jy_creditshop/goods_detail/main/id='+pagedata.goods.id)" class="external">
                <div class="fui-list">
                    <div class="fui-list-media">
                        <img src="{{tomedia(pagedata.goods.thumb)}}" alt="{{pagedata.goods.title}}" class="round">
                    </div>
                    <div class="fui-list-inner">
                        <div class="text goodstitle">{{pagedata.goods.title}}</div>
                        <div ng-if="pagedata.post.optionid>0" class='subtitle' style="font-size:0.6rem;color:#999;">规格：{{pagedata.goods.optiontitle}}</div>
                    </div>
                    <div class='fui-list-angle' style="width:auto;font-size:0.6rem">
                        <span ng-if="pagedata.post.taocan.money<=0" class='marketprice'>
                            {{pagedata.post.taocan.credit}}{{pagedata.post.taocan.credit_title||'积分'}}<br />
				            <br/>   x {{pagedata.post.num}}
                        </span>
						<span ng-if="pagedata.post.taocan.money>0" class='marketprice'>
                            {{pagedata.post.taocan.credit}}{{pagedata.post.taocan.credit_title||'积分'}}<br />&yen;{{pagedata.post.taocan.money}}金额
				            <br/>   x {{pagedata.post.num}}
                        </span>
                    </div>
                </div>
            </a>
        </div>    
        <div ng-if="pagedata.goods.type==0 && pagedata.goods.stores.length>0" class='fui-according-group'>
            <div class='fui-according'>
                <div class='fui-according-header'>
                    <i class='icon icon-shop'></i>
                    <span class="text">适用门店</span>
                    <span class="remark"><div class="badge">{{pagedata.goods.stores.length}}</div></span>
                </div>
				<div class="fui-list-group"  id="carrierInfo" style="margin: 0">
					<a class="fui-list" ng-if="$index<=3" ng-repeat="item in pagedata.goods.stores" href="javascript:;" ng-click="pagedata.post.storeid=item.id;pagedata.selectstore = item;">
						<div class="fui-list-media">
							<i class="icon icon-map"></i>
						</div>
						<div class="fui-list-inner">
							<div class="subtitle" >
								<span class='realname'>{{item.title}}</span>
								
							</div>
							<div class="text address">地址：<span style="color:red">{{item.pcd.province}}</span>({{item.pcd.district}} {{item.pcd.street}} {{item.address}})</div>
						</div>
					</a>
				</div>
            </div>
		</div>
        <div class='fui-cell-group'>
            <div class="fui-cell">
                <div class="fui-cell-label">商品小计</div>
                <div class="fui-cell-info"></div>
                <div class="fui-cell-remark noremark">{{pagedata.post.totalcredit}}{{pagedata.post.taocan.credit_title||'积分'}} + &yen;{{pagedata.post.totalprice}}</div>
            </div>
            <div ng-if="pagedata.order.dispatchprice>0" class="fui-cell">
                <div class="fui-cell-label">运费</div>
                <div class="fui-cell-info"></div>
                <div ng-if="pagedata.isarray_dispatch==1" class="fui-cell-remark noremark dispatchprice">{{pagedata.goods.dispatch.min}} ~ {{pagedata.goods.dispatch.max}} 元  </div>
                <div ng-if="pagedata.order.dispatchprice==0" class="fui-cell-remark noremark dispatchprice">包邮  </div>
                <div ng-if="pagedata.order.dispatchprice!=0" class="fui-cell-remark noremark dispatchprice"> &yen;{{pagedata.order.dispatchprice}} 元</div>
            </div>
			<div ng-if="pagedata.goods.set_credit1>0" class="fui-cell">
                <div class="fui-cell-label">赠送积分</div>
                <div class="fui-cell-info"></div>
                <div class="fui-cell-remark noremark">{{pagedata.goods.set_credit1}}积分</div>
            </div>
			<div class="fui-cell">
				<div class="fui-cell-label" style="width:100px">买家留言</div>
			</div>
			<div class="fui-cell" style="padding-top:0">
				<div class="fui-cell-info">
					<textarea rows="5" placeholder="有什么话想对卖家说?" ng-model="pagedata.post.remark"></textarea>
				</div>
			</div>
        </div>
    </div>

    <div class='fui-footer fui-navbar order-create-checkout' style=" z-index: 108;">
        <p class="nav-item" style="width:10%;text-align: left;padding:0.3rem;font-size:0.7rem;">
            需付{{ifelse(pagedata.goods.isverify==0 && pagedata.goods.type==0 && pagedata.goods.goodstype==0 && pagedata.order.dispatchprice>0,'（含运费）','')}}：
            <span class="text-danger2 red" style="background: none;">
               {{pagedata.post.totalcredit}}{{pagedata.post.taocan.credit_title||'积分'}}
              <span ng-if="pagedata.post.endprice" class="moneydispatch">+&yen;{{pagedata.post.endprice}}</span>
			  <span ng-if="pagedata.post.ratefee>0" style="font-size:0.55rem">(手续费:{{pagedata.post.ratefee}}{{pagedata.post.taocan.credit_title||'积分'}})</span>
            </span>
        </p>
        <a ng-if="!pagedata.order_id" href='javascript:;' ng-click="pagedata.pay()" class="nav-item btn btn-danger buybtn" id="openActionSheet">立即支付</a>
		<a ng-if="pagedata.order_id" href='javascript:;' ng-click="access_json('jy_creditshop/log_detail/main/id='+pagedata.order_id)" class="nav-item btn btn-danger buybtn" id="openActionSheet">查看订单</a>
    </div>
</div>
<div ng-if="pagedata.modal_address==1" class="popup">
	<div class="popup-body">
		<div class="popup-bottom">
		<i class="closed icon icon-close" style="color:red;top:0.3rem" ng-click="pagedata.modal_address=0"></i>
		<div class="fui-list-group modal-swiper-y" style='margin-top:5px;background:#fff'>
			<div class="fui-list address-item" ng-repeat="item in pagedata.address_list">
				
				<div class="fui-list-inner">
					<div class="title" ng-click="pagedata.change_address(item)"><span class='realname'>{{item.name}}</span> <span class='mobile'>{{item.mobile}}</span></div>
					<div class="text" ng-click="pagedata.change_address(item)"><span class='address'>{{item.province}} {{item.city}} {{item.district}} {{item.address}}</span></div>
					<div class='bar' >
						<span class='pull-right'>
							<a class="external" href="javascript:;" ng-click="pagedata.edit_address=1;pagedata.item.address=item;pagedata.isaddaddress=0">
							<i class='icon icon-bianji'></i> 编辑
							</a>
							<a class='external' href="javascript:;" ng-click="pagedata.del_address($index)">
							<i class='icon icon-shanchu'></i> 删除
							</a>
						</span>
						<label class='radio-inline'  ng-click="pagedata.setaddress($index)">
							<input type="radio" class="fui-radio  fui-radio-danger" ng-checked="item.isdefault==1"/> 设置默认
						</label>
					</div>
				</div>
			</div>
		</div>
		<div class='fui-navbar'>
			<a class="nav-item btn btn-danger external" ng-click="pagedata.edit_address=1;pagedata.isaddaddress=1"><i class="icon icon-tianjia" style="font-size:32rpx"></i> 添加地址</a>
		</div>
		</div>
	</div>
</div>
<div ng-if="pagedata.edit_address==1" class="popup">
	<div class="popup-body">
		<div class="popup-center">
			<div class='fui-cell-group modal-swiper-y'>
				<div class="fui-cell">
					<div class="fui-cell-label" style="width:100px;font-size:0.9rem">添加地址</div>
				</div>
                <div class='fui-cell'>
                    <div class='fui-cell-label'>收件人</div>
                    <div class='fui-cell-info'><input type="text" ng-model="pagedata.item.address.name" placeholder="收件人" class="fui-input"/></div>
                </div>
                <div class='fui-cell'>
                    <div class='fui-cell-label'>联系电话</div>
                    <div class='fui-cell-info'><input type="tel" ng-model="pagedata.item.address.mobile" placeholder="联系电话"  class="fui-input"/></div>
                </div>
                <div class="fui-cell">
					<div class="fui-cell-label ">地区</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.item.address.pcd.province" class="form-control tpl-province">
						<option value="" selected="selected">省份</option>
						<option ng-repeat="(value,data) in pagedata.province" value="{{value}}" ng-selected="pagedata.item.address.pcd.province==value">{{value}}</option>
						</select>
					</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.item.address.pcd.city" class="form-control tpl-city">
						<option value="" selected="selected">城市</option>
						<option ng-repeat="(value,data) in pagedata.province[pagedata.item.address.pcd.province]" value="{{value}}" ng-selected="pagedata.item.address.pcd.city==value">{{value}}</option>
						</select>
					</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.item.address.pcd.district" class="form-control tpl-district">
						<option value="" selected="selected">区县</option>
						<option ng-repeat="(value,data) in pagedata.province[pagedata.item.address.pcd.province][pagedata.item.address.pcd.city]" value="{{value}}" ng-selected="pagedata.item.address.pcd.district==value">{{value}}</option>
						</select>
					</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.item.address.pcd.street" class="form-control tpl-district">
						<option value="" selected="selected">街道</option>
						<option ng-repeat="value in pagedata.province[pagedata.item.address.pcd.province][pagedata.item.address.pcd.city][pagedata.item.address.pcd.district]" value="{{value}}" ng-selected="pagedata.item.address.pcd.street==value">{{value}}</option>
						</select>
					</div>
				</div>
                <div class='fui-cell'>
                    <div class='fui-cell-label'>详细地址</div>
                    <div class='fui-cell-info'><input type="text" ng-model="pagedata.item.address.address" placeholder='街道，楼牌号等'  class="fui-input"/></div>
                </div>
            </div>
			<div class="fui-navbar">
				<a href="javascript:;" ng-click="pagedata.add_address();" class="nav-item btn btn-danger confirmbtn">确定</a>
			</div>
			<i ng-click="pagedata.edit_address=0" class="closed icon icon-cuowu"></i>
		</div>
	</div>
</div>	
<div ng-if="pagedata.showstores" class="popup">
	<div class="popup-body">
		<div class="popup-center">
			<i class="closed icon icon-cuowu" ng-click="pagedata.showstores=false"></i>
			<div class="fui-list-group"  style="margin: 0">
					<a class="fui-list" ng-repeat="item in pagedata.goods.stores" href="javascript:;" ng-click="pagedata.showstores=false;pagedata.post.storeid=item.id;pagedata.selectstore = item;">
						<div class="fui-list-media">
							<i class="icon icon-map"></i>
						</div>
						<div class="fui-list-inner">
							<div class="subtitle" >
								<span style="overflow: hidden;">线下门店</span>
								<span class='realname'>{{item.title}}</span>
								
							</div>
							<div class="text address">地址：<span style="color:red">{{item.pcd.province}}</span>({{item.pcd.district}} {{item.pcd.street}} {{item.address}})</div>
						</div>
					</a>
			</div>
		</div>
	</div>
</div>
<div ng-include="sys_html('_creditmore')"></div>
<script>
scope.pagedata.setaddress=function(index){
	var id =scope.pagedata.address_list[index].id
	scope.get('core/member.address/set/id='+id+'&get=1',function(res){
		for(var i in scope.pagedata.address_list){
				scope.pagedata.address_list[i].isdefault=0
		}
		scope.pagedata.address_list[index].isdefault=1
		scope.pagedata.post.addressid=id
		scope.pagedata.modal_address=0;
		scope.message('设置成功');
		scope.$evalAsync();
	});
}
scope.pagedata.del_address=function(index){
	var id =scope.pagedata.address_list[index].id
	scope.get('core/member.address/del/id='+id+'&get=1',function(res){
		scope.pagedata.address_list.splice(index,1);
		scope.message('删除成功');
		scope.$evalAsync();
	});
}
scope.pagedata.get_addresslist=function(){
	scope.pagedata.item.address.res=1
	scope.get('core/member.address/',function(res){
		scope.pagedata.address_list=res.list;
		scope.pagedata.modal_address=1;
		scope.$evalAsync();	
	});
}
scope.pagedata.add_address=function(){
	scope.pagedata.item.address.res=1
	if(scope.pagedata.isaddaddress==1){
		scope.pagedata.item.address.id=0;
	}
	scope.post_json('core/member.address/post/',scope.pagedata.item.address,function(res){
			console.log(res);
			scope.pagedata.item.addressid=res;
			scope.pagedata.post.addressid =res;
			scope.get('jy_creditshop/create/get_freight/showbaoyou=1&addressid='+res,function(freight){
				console.log(freight);
				scope.pagedata.post.endprice=parseFloat(scope.pagedata.post.endprice)-parseFloat(scope.pagedata.order.dispatchprice)+parseFloat(freight.fee);
				scope.pagedata.order.dispatchprice=freight.fee;
				scope.pagedata.post.dispatchprice=freight.fee;
				scope.pagedata.order.addbaoyoufee=freight.addbaoyoufee;
				scope.pagedata.order.isonebaoyou=freight.isonebaoyou;
				scope.pagedata.edit_address=0;
				scope.pagedata.modal_address=0;
				scope.pagedata.order.outarea=freight.outarea;
				scope.$evalAsync();
			});
	});
}
scope.pagedata.change_address=function(res){
	console.log(res);
	scope.pagedata.item.address=res;
	scope.pagedata.item.addressid=res.id;
	scope.pagedata.post.addressid=res.id;
	scope.get('jy_creditshop/create/get_freight/showbaoyou=1&addressid='+res.id,function(freight){
		console.log(freight);
		scope.pagedata.post.endprice=parseFloat(scope.pagedata.post.endprice)-parseFloat(scope.pagedata.order.dispatchprice)+parseFloat(freight.fee);
		scope.pagedata.order.dispatchprice=freight.fee;
		scope.pagedata.post.dispatchprice=freight.fee;
		scope.pagedata.order.addbaoyoufee=freight.addbaoyoufee;
		scope.pagedata.order.isonebaoyou=freight.isonebaoyou;
		scope.pagedata.modal_address=0;
		scope.pagedata.order.outarea=freight.outarea;
		scope.$evalAsync();
				
	});
	
}
scope.pagedata.uptaocan=function(item){
	scope.pagedata.post.totalprice=item.money*scope.pagedata.post.num;
	if(scope.pagedata.post.sendtype==1){
		scope.pagedata.post.endprice=scope.pagedata.post.totalprice-scope.pagedata.order.dispatchprice;
	}else{
		scope.pagedata.post.endprice=scope.pagedata.post.totalprice
	}
	scope.pagedata.post.totalcredit=item.credit*scope.pagedata.post.num;
	scope.$evalAsync();
}
scope.pagedata.pay=function(){
    scope.post_json('/create/pay/',scope.pagedata.post,function(res){
		var onemerchid=scope.pagedata.onemerchid;
		scope.pagedata.order_id=res.id;
		var success_url ='jy_creditshop/log_detail/main/id='+res.id
		scope.tool.pay(res.payid,function(res){
				if(res.type=='success'){
					scope.message('支付成功！','success',success_url);
				}else{
					scope.message('支付失败！','success',success_url);
				}
		},'','',success_url,success_url,onemerchid);
	});
}
</script>